package cn.wsalix.shop.entity;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.EntityListeners;
import javax.persistence.FetchType;
import javax.persistence.ForeignKey;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import lombok.Data;
import lombok.EqualsAndHashCode;

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import cn.anlaser.entity.SimpleEntity;
import cn.wsalix.biz.entity.Category;
import cn.wsalix.status.PriceEnum;

import com.fasterxml.jackson.annotation.JsonIgnore;

@Entity
@DynamicInsert
@DynamicUpdate
@Table(name = "SHOP_PRICE")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
@EntityListeners({ AuditingEntityListener.class })
@Data
@EqualsAndHashCode(exclude={"product"},callSuper = false)
public class Price extends SimpleEntity {

	/**
		 * 
		 */
	private static final long serialVersionUID = 8500867520550921062L;
	private int price;// 价格
	private int num;//购买数量
	private String title;// 折扣
	//private String rule;// 价格
	//private String content;//优惠
/*	private boolean original;//原始价格
*/	private int tuanNum;//团购人数
	private PriceEnum type;
	@JsonIgnore
	@ManyToOne(cascade = CascadeType.MERGE, optional = true, fetch = FetchType.LAZY)
	@JoinColumn(foreignKey = @ForeignKey(name = "FK_PRICE_PRODUCT"), name = "PRODUCT_ID")
	private Product product;
	
	@JsonIgnore
	@ManyToOne(cascade = CascadeType.MERGE, optional = true, fetch = FetchType.LAZY)
	@JoinColumn(foreignKey = @ForeignKey(name = "FK_PRICE_CATEGORY"), name = "CAT_ID")
	private Category category;
	
}